package org.embedchat.minatestcase;

import java.net.SocketAddress;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TransportType;
import org.apache.mina.common.WriteFuture;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.support.AbstractIoFilterChain;
import org.apache.mina.common.support.BaseIoSession;

public class TestIoSession extends BaseIoSession {
	
	private static Log log = LogFactory.getLog(TestIoSession.class);
	private IoFilterChain chain;
	private IoHandler handler;
	
	public TestIoSession () {
	}
	
	public TestIoSession(IoHandler handler) {
		this.handler = handler;
		chain = new AbstractIoFilterChain(this) {
			@Override
			protected void doWrite(IoSession session, WriteRequest wRequest) throws Exception {
				log.debug("doWrite: " + wRequest);
			}
			
			@Override
			protected void doClose(IoSession session) throws Exception {
				log.debug("doClose: " + session);
			}
		};
	}

	@Override
	public WriteFuture write(Object object) {
		try {
			handler.messageSent(this, object);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new WriteFuture() {

			public boolean isWritten() {
				return false;
			}

			public void setWritten(boolean arg0) {
			}

			public void addListener(IoFutureListener arg0) {
			}

			public Object getLock() {
				return null;
			}

			public IoSession getSession() {
				return null;
			}

			public boolean isReady() {
				return false;
			}

			public void join() {
			}

			public boolean join(long arg0) {
				return false;
			}

			public void removeListener(IoFutureListener arg0) {
			}
		};
	}

	
	@Override
	protected void write0(WriteRequest arg0) {
		log.debug("write0()");
		super.write0(arg0);
	}

	@Override
	protected void updateTrafficMask() {
		// TODO Auto-generated method stub
	}

	public IoService getService() {
		log.debug("getService()");
		return null;
	}

	public IoHandler getHandler() {
		log.debug("getHandler()");
		return null;
	}

	public IoSessionConfig getConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	public IoFilterChain getFilterChain() {
		return chain;
	}

	public TransportType getTransportType() {
		return null;
	}

	public SocketAddress getRemoteAddress() {
		return null;
	}

	public SocketAddress getLocalAddress() {
		return null;
	}

	public SocketAddress getServiceAddress() {
		return null;
	}

	public int getScheduledWriteRequests() {
		return 0;
	}

	public int getScheduledWriteBytes() {
		return 0;
	}

	public IoServiceConfig getServiceConfig() {
		// TODO Auto-generated method stub
		return null;
	}
}
